{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "7a8a5378",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0xa0\n",
      "0o11000\n",
      "0b100000\n",
      "38\n",
      "&\n"
     ]
    }
   ],
   "source": [
    "#进制转换\n",
    "#0b二进制binary、0o八进制octal、0x十六进制hexadecimal\n",
    "#bin转化成二进制、oct转化成八进制、hex转化成16进制\n",
    "#ord获取ASCII码值，chr用于讲码值转化成字符\n",
    "\n",
    "print(hex(160))\n",
    "print(oct(0x1200))\n",
    "print(bin(32))\n",
    "\n",
    "print(ord(\"&\"))#输入ASCII码值时要是字符串\n",
    "print(chr(38))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "acf3a0b1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9\n",
      "171\n",
      "9\n",
      "32.0\n",
      "3877.0\n"
     ]
    }
   ],
   "source": [
    "#int可以转成10进制，也可以实现取整数（直接取整数位没有四舍五入），针对整数\n",
    "#float和int的功能有相对，即可以输出浮点数，并且将各种进制整数转化成十进制浮点数\n",
    "\n",
    "print(int(\"011\",8))\n",
    "print(int(\"ab\",16))\n",
    "print(int(\"01001\",2))#注意引号！引号里面是数，外面声明进制\n",
    "\n",
    "print(float(32))\n",
    "print(float(0xf25))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "f3b58953",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "51\n",
      "50.65\n"
     ]
    }
   ],
   "source": [
    "#算数运算常用函数\n",
    "\n",
    "#round可以用来取整，或者可以保留n位小数\n",
    "print(round(50.86))\n",
    "print(round(50.645526,2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "e228c340",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(5+5j)\n",
      "7.0710678118654755\n"
     ]
    }
   ],
   "source": [
    "#complex定义复数，abs输出绝对值。也即只要使用复数表达形式必须有complex()\n",
    "\n",
    "print(complex(\"5+5j\"))#只能用j，不可以用i\n",
    "print(abs(complex(\"5+5j\")))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "e74c6566",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(4, 1)\n"
     ]
    }
   ],
   "source": [
    "# % 得到的只有余数，divmod还可以得到商，输出为元组格式\n",
    "print(divmod(9,2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "13a66286",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "32\n",
      "2\n"
     ]
    }
   ],
   "source": [
    "#pow可以得到幂的形式，第一个为底数，第二个为指数，如果有第三个则得到除以它的余数\n",
    "print(pow(2,5))\n",
    "print(pow(2,5,5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "9a38a94b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2, 3, 4, 5, 6, 7, 8]\n",
      "[2, 5, 8]\n"
     ]
    }
   ],
   "source": [
    "#range可以生成一串数，可以顺序生成，也可以等间隔生成，用list生成列表\n",
    "print(list(range(2,9)))\n",
    "print(list(range(2,9,3)))\n",
    "#第二个数表示列表到它会停止，所以输出的结果无论如何是没有这个数的"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "64b1f5be",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
